// pages/car/select/select.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		letter: ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U",
			"V", "W", "X", "Y", "Z"
		],
		showPy: 'A',
		hidden: true,
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad: function(options) {
		wx.request({
			url:getApp().globalData.http+'action=getCarIndex',
			success: (e) => {
				console.log(e)
				let a = [{
							"letter": "A",
							"data": []
						}, {
							"letter": "B",
							"data": []
						}, {
							"letter": "C",
							"data": []
						}, {
							"letter": "D",
							"data": []
						}, {
							"letter": "E",
							"data": []
						}, {
							"letter": "F",
							"data": []
						}, {
							"letter": "G",
							"data": []
						}, {
							"letter": "H",
							"data": []
						}, {
							"letter": "I",
							"data": []
						}, {
							"letter": "J",
							"data": []
						}, {
							"letter": "K",
							"data": []
						}, {
							"letter": "L",
							"data": []
						}, {
							"letter": "M",
							"data": []
						}, {
							"letter": "N",
							"data": []
						}, {
							"letter": "O",
							"data": []
						}, {
							"letter": "P",
							"data": []
						}, {
							"letter": "Q",
							"data": []
						}, {
							"letter": "R",
							"data": []
						}, {
							"letter": "S",
							"data": []
						}, {
							"letter": "T",
							"data": []
						}, {
							"letter": "U",
							"data": []
						}, {
							"letter": "V",
							"data": []
						}, {
							"letter": "W",
							"data": []
						}, {
							"letter": "X",
							"data": []
						}, {
							"letter": "Y",
							"data": []
						}, {
							"letter": "Z",
							"data": []
						}]
						console.log(a)
						e.data.data.list.forEach(function(item, index) {
							if (item.pingying.match(/^[a-zA-Z]/)[0] == 'A') {
								a[0].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'B') {
								a[1].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'C') {
								a[2].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'D') {
								a[3].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'E') {
								a[4].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'F') {
								a[5].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'G') {
								a[6].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'H') {
								a[7].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'I') {
								a[8].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'J') {
								a[9].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'K') {
								a[10].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'L') {
								a[11].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'M') {
								a[12].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'N') {
								a[13].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'O') {
								a[14].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'P') {
								a[15].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'Q') {
								a[16].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'R') {
								a[17].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'S') {
								a[18].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'T') {
								a[19].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'U') {
								a[20].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'V') {
								a[21].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'W') {
								a[22].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'X') {
								a[23].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'Y') {
								a[24].data.push(item)
							} else if (item.pingying.match(/^[a-zA-Z]/)[0] == 'Z') {
								a[25].data.push(item)
							}
						})
						console.log(a)
						this.setData({
							list: a,
							tj:e.data.data.tj
						})
			}
		})
	},
	getPy: function(e) {
		this.setData({
			hidden: false,
			showPy: e.target.id,
		})
	},
	tStart: function() {
		this.setData({
			hidden: false
		})
	},
	tMove: function(e) {
		console.log(e)
		var y = e.touches[0].clientY,
			offsettop = e.currentTarget.offsetTop,
			that = this;

		//判断选择区域,只有在选择区才会生效
		if (y > offsettop) {
			var num = parseInt((y - offsettop) / 12);
			this.setData({
				showPy: this.data.list[num].letter
			})
		};
	},
	tEnd: function() {
		this.setData({
			hidden: true,
			scrollTopId: this.data.showPy
		})
	},
	//获取点击的字母，在页面放大上展示
	getPy: function(e) {
		this.setData({
			hidden: false,
			showPy: e.target.id,
		})
	},
	//将设置到字母，赋值到scrollTopId
	setPy: function(e) {
		this.setData({
			hidden: true,
			scrollTopId: this.data.showPy
		})
	},
	xq(e) {
		console.log(e)
		wx.navigateTo({
			url:'../chex/chex?id='+e.currentTarget.dataset.id
		})
	}
})
